package com.qf.mp2202day02.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.mp2202day02.dao.UserDao;
import com.qf.mp2202day02.entity.User;
import com.qf.mp2202day02.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;

@Service
public class UserServiceImpl extends ServiceImpl<UserDao, User> implements UserService {

    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public Map<String, Object> login(String username, String password) {

        final QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();

        userQueryWrapper.eq("name",username);

        final User user = this.getOne(userQueryWrapper);

        if (user!=null){
            if (user.getEmail().equals(password)){
                final HashMap<String, Object> hashMap = new HashMap<>();
                hashMap.put("code",1);
                hashMap.put("msg","登录成功");
                return hashMap;
            }
        }


        final HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("code",-1);
        hashMap.put("msg","登录失败");
        return hashMap;
    }
}
